<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" >

<title>搭建服务器并配置相关环境 | KALUO</title>
<meta name="description" content="温故而知新">

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<link rel="shortcut icon" href="https://kaluo-zz.github.io/favicon.ico?v=1591084625855">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css">
<link rel="stylesheet" href="https://kaluo-zz.github.io/styles/main.css">



<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>

<link rel="stylesheet" href="https://unpkg.com/aos@next/dist/aos.css" />



  </head>
  <body>
    <div id="app" class="main">

      <div class="sidebar" :class="{ 'full-height': menuVisible }">
  <div class="top-container" data-aos="fade-right">
    <div class="top-header-container">
      <a class="site-title-container" href="https://kaluo-zz.github.io">
        <img src="https://kaluo-zz.github.io/images/avatar.png?v=1591084625855" class="site-logo">
        <h1 class="site-title">KALUO</h1>
      </a>
      <div class="menu-btn" @click="menuVisible = !menuVisible">
        <div class="line"></div>
      </div>
    </div>
    <div>
      
        
          <a href="/" class="site-nav">
            首页
          </a>
        
      
        
          <a href="/archives" class="site-nav">
            归档
          </a>
        
      
        
          <a href="/tags" class="site-nav">
            标签
          </a>
        
      
        
          <a href="/post/about" class="site-nav">
            关于
          </a>
        
      
    </div>
  </div>
  <div class="bottom-container" data-aos="flip-up" data-aos-offset="0">
    <div class="social-container">
      
        
      
        
      
        
      
        
      
        
      
    </div>
    <div class="site-description">
      温故而知新
    </div>
    <div class="site-footer">
      Powered by <a href="https://github.com/getgridea/gridea" target="_blank">Gridea</a> | <a class="rss" href="https://kaluo-zz.github.io/atom.xml" target="_blank">RSS</a>
    </div>
  </div>
</div>


      <div class="main-container">
        <div class="content-container" data-aos="fade-up">
          <div class="post-detail">
            <h2 class="post-title">搭建服务器并配置相关环境</h2>
            <div class="post-date">2019-06-06</div>
            
            <div class="post-content">
              <p>需要用到的软件如下：</p>
<ol>
<li>Ubuntu18.04 Server</li>
<li>Cuda 9.0</li>
<li>Cudnn 7</li>
<li>rufus-3.3p</li>
</ol>
<h2 id="安装ubuntu-1804-server版">安装Ubuntu 18.04 Server版</h2>
<p>有两种安装方式，一种是硬盘安装，另一种是U盘安装。实验室电脑原先系统是Ubuntu 16.04 Desktop版。</p>
<h3 id="硬盘安装">硬盘安装</h3>
<p>下载Ubuntu 18.04 Server iso镜像文件，放置于系统根目录下。重启电脑，按‘c’键进入grub2（按‘Esc’退出grub2命令行模式）。输入命令：</p>
<pre><code class="language-bash">loopback loop (hd3, gpt2)/ubuntu.iso
set root=(loop)
linux /casper/vmlinuz boot=casper iso-scan/filename=/ubuntu.iso
initrd /casper/initrd
boot
</code></pre>
<p>参考<a href="http://forum.ubuntu.org.cn/viewtopic.php?t=347622">用grub2引导ISO硬盘安装ubuntu</a>。</p>
<p>注意事项：单系统ubuntu启动默认不显示grub菜单，想要显示请参考<a href="https://blog.csdn.net/Q1302182594/article/details/51967772">开机显示grub选择菜单</a>。命令 <code>ls -l</code> 列出所有的硬盘，<code>(hd3, gpt2)</code>是我ubuntu系统所在的分区。</p>
<h3 id="u盘安装">U盘安装</h3>
<p>利用rufus制作u盘启动盘。</p>
<h2 id="配置有线无线环境">配置有线/无线环境</h2>
<p>Ubuntu18.04系统中<code>/etc/network/interface</code>已经被舍弃，取而代之的是<code>/etc/netplan</code>。</p>
<p>运行命令，安装<code>wpasupplicant</code>以及<code>network-manager</code></p>
<pre><code class="language-bash">sudo apt-get install wpasupplicant
sudo apt-get install network-manager
</code></pre>
<p>打开<code>/etc/netplan/01-netcfg.yaml</code>，将内容替换为：</p>
<pre><code class="language-bash"># This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: NetworkManager
  ethernets:
          eno1:
                  dhcp4: no
                  addresses: [192.168.0.244/24]
                  gateway4: 192.168.0.1
                  nameservers:
                          addresses: [202.38.64.1]
  wifis:
          wlx286c07973140:
                  dhcp4: no
                  addresses: [192.168.31.93/24]
                  gateway4: 192.168.31.1
                  nameservers:
                         addresses: [xxx.xxx.xxx.xxx]
                  access-points:
                          &quot;WIFI Name&quot;:
                                  password: 'password'
</code></pre>
<p>保存退出，在命令行中运行：</p>
<pre><code class="language-bash">sudo netplan apply
</code></pre>
<p>使配置生效，然后重启电脑。</p>
<p>参考链接：<a href="https://steemit.com/network/@oflyhigh/ubuntu-server-18-04-wifi">Ubuntu Server 18.04 设置WIFI上网</a></p>
<h2 id="安装python2">安装python2</h2>
<p>Ubuntu 18.04默认没有python2，输入以下命令安装：</p>
<pre><code class="language-bash">sudo apt update
sudo apt-get install python
sudo apt install python-pip
sudo apt install python3-pip
</code></pre>
<h2 id="安装open-ssh">安装open-ssh</h2>
<pre><code class="language-bash">sudo apt-get install openssh-server
</code></pre>
<h2 id="挂载u盘">挂载U盘</h2>
<p>查看所有磁盘信息：</p>
<pre><code class="language-bash">sudo fdisk -l
</code></pre>
<p>挂载U盘：</p>
<p>对于FAT32格式，<code>mount -t vfat /dev/sda /media</code></p>
<p>对于NTFS格式，<code>mount -t nfs /dev/sda /media</code></p>
<p>卸载U盘：<code>sudo umount /media</code></p>
<h2 id="安装tensorflow-gpu">安装TensorFlow-GPU</h2>
<p>参考<a href="https://blog.csdn.net/shenquanyue/article/details/82774348#_23">ubuntu18.04 安装tensoflow-gpu</a></p>
<p>注意事项：在装NVIDIA显卡驱动之前，先禁用Ubuntu系统自带的nouveau驱动。<a href="https://blog.csdn.net/u012442845/article/details/78855573">禁用 nouveau 安装 nvidia显卡驱动</a></p>
<p>**注意事项：**安装cuda和caffe时，要将环境变量写在<code>/etc/profile</code>中。如果写在<code>./bashrc</code>中，只能当前用户使用，其他用户无法使用。参考<a href="https://blog.csdn.net/ithomer/article/details/6322892">Linux 之 /etc/profile、~/.bash_profile 等几个文件的执行过程</a>。</p>
<h4 id="切换gcc版本">切换gcc版本</h4>
<p>NVIDIA驱动安装时可能会遇到gcc版本不匹配问题，到/usr/bin目录下删除原有的gcc和g++软链接：</p>
<pre><code class="language-bash">sudo rm gcc
sudo rm g++
</code></pre>
<p>如果要将gcc版本从7切换到6（当然，前提是已经安装了gcc-6），执行命令：</p>
<pre><code class="language-bash">sudo ln -s gcc-6 gcc
sudo ln -s g++-6 g++
</code></pre>

            </div>
            
              <div class="tag-container">
                
                  <a href="https://kaluo-zz.github.io/tag/q7ckOahzm" class="tag">
                    ubuntu18.04
                  </a>
                
                  <a href="https://kaluo-zz.github.io/tag/-EGjsU52C" class="tag">
                    服务器环境
                  </a>
                
                  <a href="https://kaluo-zz.github.io/tag/OX4bnktRr" class="tag">
                    切换gcc版本
                  </a>
                
              </div>
            
            
              <div class="next-post">
                <div class="next">下一篇</div>
                <a href="https://kaluo-zz.github.io/post/ce-shi">
                  <h3 class="post-title">
                    浅谈hdf5
                  </h3>
                </a>
              </div>
            

            

          </div>

        </div>
      </div>
    </div>

    <script src="https://unpkg.com/aos@next/dist/aos.js"></script>

<script type="application/javascript">

AOS.init();

hljs.initHighlightingOnLoad()

var app = new Vue({
  el: '#app',
  data: {
    menuVisible: false,
  },
})

</script>




  </body>
</html>
